package net.lzzy.algorithm.find;

public abstract class BaseSearch <T extends Comparable<? super T>>{
    T[] itmes;   //1、可接收参与排序的数据集合
    long time;        //2、可记录算法运行的时长（long字段+getter）
    int compareCount; //3、比较次数
    int compareMove;  //3、移动次数
    long directSort;  //6、排序结果


    public BaseSearch(T[] itmes) {  //1、数据集合
        this.itmes = itmes;
        compareCount = 0;
        compareMove = 0;
    }

    public BaseSearch() {
    }

    boolean equal(T a,T b) {  //4、用于比较两个元素大小的方法
        compareCount++;
        return a.compareTo(b) == 0;
    }
    int compare(T a, T b){
        compareCount++;
        return a.compareTo(b);
    }

    public  String getResult(){    //6、返回排序结果的方法
        String display ="";
        for (T i : itmes) {
            display = display.concat(i + ",");
        }
        return  display.substring(0, display.length() - 1);
    }

    public abstract  int  search(T key);   //抽象类

    public long getTime() {  //算法的运行时长
        return time;
    }
    public void setTime(long time){
        this.time=time;
    }

    public int getCompareCount() { //对比次数
        return compareCount;
    }
     void  setCompareCount(int compareCount){
        this.compareCount=compareCount;
    }

    public int getCompareMove() {  //移动次数
        return compareMove;
    }
    public void  setCompareMove(int compareMove) {
        this.compareMove=compareMove;
    }

}
